<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddDisplayOrderColumnsToArticle extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('yq_article')) {
            Schema::table('yq_article', function (Blueprint $table) {
                if (!Schema::hasColumn('yq_article', 'display_order')) {
                    $table->integer('display_order')->default(0)->comment('排序');
                }
                if (!Schema::hasColumn('yq_article', 'links')) {
                    $table->string('links',500)->default('')->comment('跳转链接');
                }
            });
        }
        if (Schema::hasTable('yq_page')) {
            Schema::table('yq_page', function (Blueprint $table) {
                if (!Schema::hasColumn('yq_page', 'links')) {
                    $table->string('links',500)->default('')->comment('跳转链接');
                }
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('yq_article', function (Blueprint $table) {
            $table->dropColumn('display_order');
            $table->dropColumn('links');
        });
        Schema::table('yq_page', function (Blueprint $table) {
            $table->dropColumn('links');
        });
    }
}
